﻿namespace Xms.Abp.Data;

public class PagedResult<T>: IPagedResult<T>
{
    public PagedResult()
    {

    }
    public PagedResult(long totalCount, int maxResultCount, int skipedCount, IReadOnlyList<T> items)
    {
        MaxResultCount = maxResultCount;
        SkipedCount = skipedCount;
        TotalCount = totalCount;
        _items = items;
    }

    public int MaxResultCount { get; }
    public int SkipedCount { get; }
    public int PageIndex
    {
        get => SkipedCount / MaxResultCount + 1;
    }
    public int PageSize
    {
        get => MaxResultCount;
    }
    public int PageCount
    {
        get
        {
            var v = TotalCount % MaxResultCount > 0 ? 1 : 0;
            return (int)(TotalCount / MaxResultCount) + v;
        }
    }
    public long TotalCount { get; set; }
    public IReadOnlyList<T> Items
    {
        get { return _items ??= new List<T>(); }
        set { _items = value; }
    }
    private IReadOnlyList<T> _items;
}
